// pages/personDetail/personDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    sex:"",
    age:"",
    phone:"",
    pic:"",
    beizhu:"",
    
    createTime:'',
    address:'',
    latitude:'',
    longitude:'',  
    status:'',

    createTime:[],


    situationId:'',
    album: [
    ],
    message:[]
  },
  goToClue(e){
    console.log(e.currentTarget.dataset.clueid)
    var clueId = e.currentTarget.dataset.clueid
    wx.navigateTo({
      url: '../detailClue/detailClue?clueId='+clueId,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var flag = 0;
    wx.showLoading({
      title: '正在加载数据',
    })
    this.setData({
      situationId:options.situationId
    })
    wx.request({
      url: app.globalData.Baseip+':8881/situation/alreadyJoin?situationId='+options.situationId,
      header: {
        Authorization:app.globalData.header
       },
      method:'GET',
      success:res=>{
        console.log('join',res)
        this.setData({
          alreadyJoin:res.data.data
        })
      

      },
      fail:function(err){
        console.log('join',err)
      }
    })
    wx.request({
      url: app.globalData.Baseip+':8881/situation/getSituationById?situationId='+options.situationId,
     
      method:'GET',
      header: {
        Authorization:app.globalData.header
      },
      success:res=>{
        var data = res.data.data;
        console.log(res)
        this.setData({
          age:data.age,
          createTime:data.createTime,
          address:data.lostAddress,
          latitude:data.lastFindLatitude,
          longitude:data.lastFindLongitude,
          name:data.name,
          beizu:data.other,
          phone:data.phone,
          sex:data.sex,
          status:data.status,
          album:data.album
        })
        flag = flag +1
        if(flag == 2){
          wx.hideLoading({
            success: (res) => {},
          })
        }
       
      },
      fail:function(err){
        console.log(err)
        wx.hideLoading({
          success: (res) => {},
        })
      }
    })
    
    // 获取线索
    wx.request({
      url: app.globalData.Baseip+':8882/clue/getSituationClue?situationId='+options.situationId,
     
      method:'GET',
      header: {
        Authorization:app.globalData.header
      },
      success:res=>{
        var data = res.data.data;
        console.log("clue",data)
        this.setData({
          message:data
        })
        flag = flag + 1
        if(flag==2){
          wx.hideLoading({
            success: (res) => {},
          })
        }
      
      },
      fail:function(err){
        console.log(err)
        wx.hideLoading({
          success: (res) => {},
        })
      }
    })

  },
  preView(e){
    // console.log(e.currentTarget.dataset.src)
    wx.previewImage({
      urls: this.data.album, //需要预览的图片http链接列表，注意是数组
      current: '', // 当前显示图片的http链接，默认是第一个
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  


  },
  gotoTeam(){
    //判断是否为志愿者或者家属

    //判断是否已经加入

    //如果是则跳转
    wx.request({
      url: app.globalData.Baseip+':8881/situation/joinSituation?situationId='+this.data.situationId,
     
      method:'POST',
      header: {
        Authorization:app.globalData.header
      },
      success:res=>{
      
      
      },
      fail:function(err){
        
      }
    })


    wx.navigateTo({
      url: '../mysearch/mysearch?id='+this.data.situationId,
      success: (result) => {},
      fail: (res) => {},
      complete: (res) => {},
    })
      
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})